﻿using System.Data.Entity;
using Microsoft.AspNet.Identity.EntityFramework;
using SDCloudSolution.SDCloud.DataLayer.Interfaces;
using SDCloudSolution.SDCloud.Entities.Identity;

namespace SDCloudSolution.SDCloud.DataLayer.Identity
{
    public class ApplicationIdentityDbContext : IdentityDbContext<ApplicationUserEntity, ApplicationRoleEntity, int, ApplicationUserLoginEntity, ApplicationUserRoleEntity, ApplicationUserClaim>
    {
        public ApplicationIdentityDbContext(IIdentityDbConnectionStringProvider connectionStringProvider)
            : base(connectionStringProvider.IdentityDbConnectionString)
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder
                .Entity<ApplicationUserEntity>()
                .ToTable("user");

            modelBuilder
                .Entity<ApplicationRoleEntity>()
                .ToTable("role");

            modelBuilder
                .Entity<ApplicationUserRoleEntity>()
                .ToTable("user_roles");

            modelBuilder
                .Entity<ApplicationUserClaim>()
                .ToTable("user_claims");

            modelBuilder
                .Entity<ApplicationUserLoginEntity>()
                .ToTable("user_external");
        }
    }
}
